<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %> 

 
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <title>采购项目${name}</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %> 
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
	<input id="opType" type="hidden" value="<%= request.getParameter("opType") %>" />
    <section class="content-header">
        <h1>
   <c:choose>
   	<c:when test="${flag == 1}">
   		采购项目新增
   	</c:when>
   	<c:otherwise>
   		采购项目编辑
   	</c:otherwise>
   </c:choose>     
        </h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">采购项目管理</a></li>
            <li class="active"><a href="#">项目管理</a></li>
        </ol>
    </section>
    <!-- 项目信息填写开始 -->
    <section class="content" >
    	<div class=" box box-success" id="projTag" >
            <form id="form" action="${ctx}/bidProject/dataPurEdit.html" method="post" class="form-horizontal" >
            	<input type="hidden" id="projId" name="projId" value='<c:out value="${bidProject.projId}"></c:out>' />
            	<input type="hidden"  name="status" value='<c:out value="${bidProject.status}"></c:out>' />
	          	<input type="hidden"  name="createDatetime" value='${fn:substring(bidProject.createDatetime, 0, 19)} ' />
	            <input type="hidden"  name="createUser" value='<c:out value="${bidProject.createUser}"></c:out>' /> 
                <div class="box-body">
                	<c:if test="${bidProject.projId !=null}">
	                    <div class="form-group form-group-xs" style="height:24px">
			                        <label for="inputTextAlter4" class="col-sm-2 control-label"><span class="required">*</span>项目编号：</label>
			                        <div class="col-sm-4">
			                           	<input readonly="true" class="form-control" id="projCode" name="projCode" placeholder="项目编码" type="text" value="${bidProject.projCode }" maxlength="50"><span class="required" id="projCodeFail"></span>
			                        </div>
	                    </div>
                    </c:if> 
                    <div class="form-group form-group-xs" style="height:24px">
                        <label for="inputTextAlter4" class="col-sm-2 control-label"><span class="required">*</span>项目名称：</label>
                        <div class="col-sm-4">
                           	<input class="form-control" id="name" name="name" placeholder="项目名称" type="text" value="${bidProject.name }" maxlength="42"><span class="required" id="projNameFail"></span>	
                        </div>
                        <label for="inputTextAlter4" class="col-sm-2 control-label"><span class="required">*</span>项目类型：</label>
                       	<div class="col-sm-4">
                           	<select class="form-control" name="projCat" id="projCat">
                           		<option value="">请选择</option>
                        		<c:forEach items="${list}" var="dicSys">
                        		    <c:choose>
                        		        <c:when test="${dicSys.dicCode != 5}">
                        			        <option value="${dicSys.dicCode}" ${bidProject.projCat == dicSys.dicCode ? "selected='true'":""}>${dicSys.dicName}</option>
                        			    </c:when>
                        			</c:choose>
                        		</c:forEach>
                          	</select>
                       	</div>
                    </div>
                    <div class="form-group form-group-xs">
	                        <label for="inputTextAlter4" class="col-sm-2 control-label"><span class="required">*</span>采购日期：</label>
	                        <div class="col-sm-4"> 
		                        <table style="width:100%;">
		                             <tr>
		                                <td style="width:50%">
		                                     <input class="form-control" id="starttime" name="starttime" type="text" readonly="readonly" placeholder="yyyy-MM-dd"  
		                               onFocus="var endDate=$dp.$('endtime');WdatePicker({maxDate:'#F{$dp.$D(\'endtime\')}'})" value='${fn:substring(bidProject.starttime, 0, 10)}' />
		                                </td>
		                                <td>&nbsp;-&nbsp;</td>
		                                <td style="width:50%">
		                                   <input class="form-control" id="endtime" name="endtime"  type="text" readonly="readonly"   placeholder="yyyy-MM-dd" 
		                              onFocus="WdatePicker({minDate:'#F{$dp.$D(\'starttime\')}',})" value='${fn:substring(bidProject.endtime, 0, 10)}' />
		                                </td>
		                              </tr>
		                           </table>
	                        </div> 
	                        <label for="inputTextAlter4" class="col-sm-2 control-label"><span class="required">*</span>采购计划申报日期：</label>
	                        <div class="col-sm-4"> 
	                            <table style="width:100%;">
	                                 <tr>
	                                    <td style="width:50%">
	                                         <input class="form-control" id="planStartDatetime" name="planStartDatetime" type="text" readonly="readonly" placeholder="yyyy-MM-dd"  
	                                   onFocus="var endDate=$dp.$('planEndDatetime');WdatePicker({maxDate:'#F{$dp.$D(\'planEndDatetime\')}'})" value='${fn:substring(bidProject.planStartDatetime, 0, 10)}' />
	                                    </td>
	                                    <td>&nbsp;-&nbsp;</td>
	                                    <td style="width:50%">
	                                       <input class="form-control" id="planEndDatetime" name="planEndDatetime"  type="text" readonly="readonly"  placeholder="yyyy-MM-dd" 
	                                   onFocus="WdatePicker({minDate:'#F{$dp.$D(\'planStartDatetime\')}'})" value='${fn:substring(bidProject.planEndDatetime, 0, 10)}' />
	                                    </td>
	                                  </tr>
	                               </table>
	                        </div>                          	
                    	
                    </div>
                    
                    <div class="form-group form-group-xs">
                       	<label class="col-sm-2 text-right">项目范围：</label>
                        <div class="col-sm-4 "  >
                        	 <select class="form-control" name="projRange" id="projRange" onchange="queryHospCount(this[selectedIndex].value);" >
	                           		<option value="0">全部</option>
	                        		<c:forEach items="${list2}" var="dicSys">
	                        			<c:if test="${dicSys.dicCode==1 || dicSys.dicCode==2}">
	                        				<option value="${dicSys.dicCode}" ${bidProject.projRange == dicSys.dicCode ? "selected='true'":""}>${dicSys.dicName}</option>
	                        			</c:if>
	                        		</c:forEach>
                          	</select>
                        </div>
		                        <label class="col-sm-2 text-right"> 
		                          <span id="checkText" ></span>  ：</label>
		                        <div class="col-sm-4 "><span class="required" id="hospCount" ><c:out value="${hospCount}"></c:out></span></div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="inputTextAlter4" class="col-sm-2 control-label">项目简介：</label>
                        <div class="col-sm-10">
                        	<textarea id="projIntro" name="projIntro" class="form-control" placeholder="项目简介(不超过1300个字)" maxlength="1333">${bidProject.projIntro}</textarea>
                        </div>
                    </div>
                   
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">备&nbsp;&nbsp;注：</label>
                        <div class="col-sm-10">
                            <textarea class="form-control"  id="remark" name="remark" placeholder="备注(不超过1300个字)" maxlength="1333">${bidProject.remark}</textarea>
                        </div>
                    </div>
                </div>
                <div class="box-footer text-center">
                   	   	<button type="button" class="btn btn-success btn-sm" onclick="complete();"> <spring:message code="message.button.saveSpacing"/> </button>
          				<a href="${ctx}/bidProject/toPurList.html" class="btn btn-danger btn-sm"> <spring:message code="message.button.getBackSpacing"/> </a>
                </div>
            </form>
        </div>
    <!-- 项目信息填写结束 -->
    </section>
    <!-- 选择配送企业结束 -->
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
    
	    //加载页面光标在名字框内，位于第一个
	    $("#name").focus();
    
	    $(function(){
	    	$("form#form :input").change(function(){
        		$("form#form").data("changed",true);
        	})
        	$(".form-control").change(function(){
        		$("form#form").data("changed",true);
        		console.log($("form#form").data("changed"));
        	})
        	
	    })
    	var isAdd = false;
    	var info ="是否保存项目信息？";
        var hospCount="${hospCount}";
        var compCount="${compCount}";
    	$(document).ready(function() {
    		//判断是编辑还是新增
    		var projId = $('#projId').val();
    		if (projId==null || projId ==""){
    			isAdd=true;
    		}else{
    			$('#projRange').attr("disabled","disabled");
    		}
	    });
	
    	
	    
        /*完成*/
        function complete(){
        	if(!validate()){
        		return;
        	}
        	if(isAdd){
        		var temp = $("#projRange :selected").text();
        		if(temp=="全部"){
        			temp="所有医疗机构"
        		}
        		info="是否保存项目信息？<br/>关联"+temp+"："+hospCount+"家<br/>关联配送企业："+compCount+"家";
        	}
        	  $.HN.message.confirm(info, '', '').on(function (e) {
	              if (e) {
	            	   $("#form").ajaxSubmit({
	                        dataType : "json",
	                        timeout: 10000,
	                        success : function(result) {
	                            if (result.success) {
	                            	   top.$.alert("保存成功！", "success");
	                            	   setTimeout(function(){
	                            		   location.href="${ctx}/bidProject/toPurList.html";
	                            	   }, 500);
	                            } else {
	                            	 top.$.HN.message.alert(result.msg || "保存失败！", "", "error");
	                            }
	                        }
	                    });

	                  
	              }
	    	  });
        }
        function queryHospCount(_val){
        	  $.post("${ctx}/bidProject/queryPurHospCount.html",{"projRange":_val},function(result){
                  if (result.success) {
                	  hospCount=result.rows;
                	  $('#hospCount').html(hospCount);
                	 
                	  
                	  var checkText=$("#projRange").find("option:selected").text();
                	  if(checkText=="全部"){
                		  $('#checkText').html("全部医疗机构数目");  
                	  }else  {
                		  $('#checkText').html(checkText + "数目");  
                		  
                	  }
                  }
              },"json");
        }
        
        
          
        
        //编辑页面获取select值
          var checkText=$("#projRange").find("option:selected").text();
          if(checkText=="全部"){
              $('#checkText').html("全部医疗机构数目");  
          }else  {
              $('#checkText').html(checkText + "数目");  
          } 
          
          

        function validate() {
        	console.log($("form#form").data("changed"));
        	if(!isAdd){
        		if(!$("form#form").data("changed")){
    				top.$.HN.message.alert("数据未修改，无需保存！", "", "warn");
        			return false;  		
            	}
        	}
        	var name = $.trim($("#name").val());
        	if (name == null || name == "") {
        		top.$.HN.message.alert("项目名称不能为空！", "", "warn");
        		$("#name").focus();
        		return false;
        	}else if(name.length > 42){
        		top.$.HN.message.alert("项目名称太长！", "", "warn");
        		return false;
        	}
        	var projCat = $.trim($("#projCat").val());
        	if (projCat == null || projCat == "") {
        		top.$.HN.message.alert("请选择项目类型！", "", "warn");
        		$("#projCat").focus();
        		return false;
        	}
        	var starttime = $.trim($("#starttime").val());
        	if (starttime == null || starttime == "") {
        		top.$.HN.message.alert("请选择采购开始时间！", "", "warn");
        		$("#starttime").focus();
        		return false;
        	}
        	var endtime = $.trim($("#endtime").val());
        	if (endtime == null || endtime == "") {
        		top.$.HN.message.alert("请选择采购结束时间！", "", "warn");
        		$("#endtime").focus();
        		return false;
        	}
         	var planStartDatetime = $.trim($("#planStartDatetime").val());
        	if (planStartDatetime == null || planStartDatetime == "") {
        		top.$.HN.message.alert("请选择计划申报开始时间！", "", "warn");
        		$("#planStartDatetime").focus();
        		return false;
        	}
        	var planEndDatetime = $.trim($("#planEndDatetime").val());
        	if (planEndDatetime == null || planEndDatetime == "") {
        		top.$.HN.message.alert("请选择计划申报结束时间！", "", "warn");
        		$("#planEndDatetime").focus();
        		return false;
        	}
        	var projIntro = $.trim($("#projIntro").val());
            if (projIntro != null && projIntro != "") {
            	if(projIntro.length > 1300){
            		top.$.HN.message.alert("项目简介过长！", "", "warn");
            		$("#projIntro").focus();
                    return false;
                }
            }
            var remark = $.trim($("#remark").val());
            if (remark != null && remark != "") {
            	if(remark.length > 1300){
            		top.$.HN.message.alert("备注信息过长！", "", "warn");
            		$("#remark").focus();
                    return false;
                }
            }
            return true;
        }
    </script>
</body>
</html>